import type { VbenFormSchema } from '#/adapter/form';
import type { VxeTableGridOptions } from '#/adapter/vxe-table';
import type { BaseinfoProductApi } from '#/api/csyt/baseinfoproduct';

import { DICT_TYPE, getDictOptions } from '#/utils';

export function useFormSchema(): VbenFormSchema[] {
  return [];
}

/** 列表的搜索表单 */
export function useGridFormSchema(): VbenFormSchema[] {
  return [
    {
      fieldName: 'productName',
      label: '产品名称',
      component: 'Input',
      componentProps: {
        allowClear: true,
        placeholder: '请输入产品名称',
      },
    },
    {
      fieldName: 'productNo',
      label: '产品编号',
      component: 'Input',
      componentProps: {
        allowClear: true,
        placeholder: '请输入产品编号',
      },
    },
    {
      fieldName: 'productPhoto',
      label: '产品封面',
      component: 'Input',
      componentProps: {
        allowClear: true,
        placeholder: '请输入产品封面',
      },
    },
    {
      fieldName: 'groupId',
      label: '系列ID',
      component: 'Select',
      componentProps: {
        allowClear: true,
        options: getDictOptions(
          DICT_TYPE.CSYT_BASEINFO_PRODUCT_GROUP,
          'number',
        ),
        placeholder: '请输入系列ID',
      },
    },
    {
      fieldName: 'type',
      label: '产品类型',
      component: 'Select',
      componentProps: {
        allowClear: true,
        options: getDictOptions(DICT_TYPE.CSYT_BASEINFO_PRODUCT_TYPE, 'number'),
        placeholder: '请选择产品类型',
      },
    },
    {
      fieldName: 'scope',
      label: '应用领域',
      component: 'Input',
      componentProps: {
        allowClear: true,
        placeholder: '请输入应用领域',
      },
    },
    {
      fieldName: 'priceType',
      label: '计费类型',
      component: 'Select',
      componentProps: {
        allowClear: true,
        options: getDictOptions(
          DICT_TYPE.CSYT_BASEINFO_PRODUCT_SCOPE,
          'number',
        ),
        placeholder: '请选择应用领域',
      },
    },
    {
      fieldName: 'tags',
      label: '关键词',
      component: 'Select',
      componentProps: {
        allowClear: true,
        options: getDictOptions(DICT_TYPE.CSYT_BASEINFO_PRODUCT_TAG, 'number'),
        placeholder: '请选择关键词',
        mode: 'multiple', // 启用多选功能
      },
    },
    {
      fieldName: 'productStatus',
      label: '产品状态',
      component: 'Select',
      componentProps: {
        allowClear: true,
        options: [],
        placeholder: '请选择产品状态',
      },
    },
  ];
}

/** 列表的字段 */
export function useGridColumns(): VxeTableGridOptions<BaseinfoProductApi.BaseinfoProduct>['columns'] {
  return [
    { type: 'checkbox', width: 40 },
    {
      field: 'id',
      title: '序号',
      minWidth: 120,
    },
    {
      field: 'productName',
      title: '产品名称',
      minWidth: 120,
    },
    {
      field: 'productNo',
      title: '产品编号',
      minWidth: 120,
    },
    {
      field: 'productPhoto',
      title: '产品封面',
      minWidth: 120,
      cellRender: {
        name: 'CellImage',
      },
    },
    {
      field: 'groupId',
      title: '系列ID',
      minWidth: 120,
      cellRender: {
        name: 'CellDict',
        props: { type: DICT_TYPE.CSYT_BASEINFO_PRODUCT_GROUP },
      },
    },
    {
      field: 'type',
      title: '产品类型',
      minWidth: 120,
      cellRender: {
        name: 'CellDict',
        props: { type: DICT_TYPE.CSYT_BASEINFO_PRODUCT_TYPE },
      },
    },
    {
      field: 'scope',
      title: '应用领域',
      minWidth: 120,
      cellRender: {
        name: 'CellDict',
        props: { type: DICT_TYPE.CSYT_BASEINFO_PRODUCT_TYPE },
      },
    },
    {
      field: 'priceType',
      title: '计费类型',
      minWidth: 120,
      cellRender: {
        name: 'CellDict',
        props: { type: DICT_TYPE.CSYT_BASEINFO_PRODUCT_PRICE_TYPE },
      },
    },
    {
      field: 'tags',
      title: '关键词',
      minWidth: 120,
    },
    {
      field: 'productStatus',
      title: '产品状态',
      minWidth: 120,
      cellRender: {
        name: 'CellDict',
        props: { type: DICT_TYPE.CSYT_BASEINFO_PRODUCT_STATUS },
      },
    },
    {
      field: 'createTime',
      title: '创建时间',
      minWidth: 120,
      formatter: 'formatDateTime',
    },
  ];
}
